package com.micro.service.common.utils;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.util.Map;

/**
 * @author lvxiucai
 * @description
 * @date 2020/1/3
 */
@Slf4j
public class HttprequestUtils {


    public static String readJSONString(HttpServletRequest request) {
        StringBuffer json = new StringBuffer();
        String line = null;
        try {
            BufferedReader reader = request.getReader();
            while ((line = reader.readLine()) != null) {
                json.append(line);
            }

        } catch (Exception e) {
            log.error("readJSONString转换异常：{}",e);
        }
        return json.toString();
    }

    public static Map<String,Object> getRequestMap(HttpServletRequest request){
        StringBuffer json = new StringBuffer();
        String line = null;
        try {
            BufferedReader reader = request.getReader();
            while ((line = reader.readLine()) != null) {
                json.append(line);
            }

            return JsonUtil.fromJSON(json.toString(),Map.class);
        } catch (Exception e) {
            log.error("getJSONObject转换异常：{}",e);
        }

        return null;
    }

}
